package com.xuzao.developer.dao.impl;

import com.xuzao.developer.tools.base.BaseServiceSupport;
import com.xuzao.developer.utils.DateUtil;
import com.xuzao.developer.base.model.PlanUpdateLog;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuzao.developer.base.criteria.PlanUpdateLogCriteria;
import com.xuzao.developer.tools.entity.Pager;
import com.xuzao.developer.mapper.PlanUpdateLogMapper;
import com.xuzao.developer.dao.PlanUpdateLogDao;

import javax.annotation.Resource;

import com.xuzao.developer.dto.PlanUpdateLogDTO;
import jodd.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


/**
 * @description 
 * @author xuzao
 * @date 2019-08-22 11:44:48
 **/
@Service("planUpdateLogDao")
public class PlanUpdateLogDaoImpl extends BaseServiceSupport<PlanUpdateLog> implements PlanUpdateLogDao {

	@Resource
	private PlanUpdateLogMapper planUpdateLogMapper;


	@Override
	public PageInfo<PlanUpdateLog> list(PlanUpdateLogDTO dto, Pager pager) {
		PlanUpdateLogCriteria criteria = this.assemblyQuerycond(dto);
		if (null != pager) {
			if (null != pager.getPageSize() && null != pager.getPageCurrent()) {
				PageHelper.startPage(pager.getPageCurrent(), pager.getNumPerPage());
			}
		}
		criteria.setOrderByClause("create_time desc");
		PageInfo<PlanUpdateLog> pageInfo = new PageInfo<>(this.planUpdateLogMapper.selectByExample(criteria));
		return pageInfo;
	}

	//通用查询方法条件组装
	public PlanUpdateLogCriteria assemblyQuerycond(PlanUpdateLogDTO dto) {
		PlanUpdateLogCriteria criteria = new PlanUpdateLogCriteria();
		PlanUpdateLogCriteria.Criteria c = criteria.createCriteria();

		if (null != dto) {
			if (dto.getProjectId()!=null){
				c.andProjectIdEqualTo(dto.getProjectId());
			}
			if (StringUtils.isNotBlank(dto.getUpdateName())){
				c.andUpdateNameLike("%"+dto.getUpdateName()+"%");
			}
			if (StringUtils.isNotBlank(dto.getStartTime())){
				c.andCreateTimeGreaterThanOrEqualTo(DateUtil.parse(dto.getStartTime()+" 00:00:00"));
			}
			if (StringUtil.isNotBlank(dto.getEndTime())){
				c.andCreateTimeLessThanOrEqualTo(DateUtil.parse(dto.getEndTime()+" 23:59:59"));
			}
		}
		return criteria;
	}
}